package com.avcdata.aoscustommade.presenter;

import com.avcdata.aoscustommade.activity.ChangePhoneOrEmail_Activity;
import com.avcdata.aoscustommade.main.BaseCallBack;
import com.avcdata.aoscustommade.model.ChangePhoneOrEmailModel;
import com.avcdata.aoscustommade.view.ChangePhoneOrEmailView;

import org.json.JSONObject;

/**
 * 修改账号的p
 * Created by zyh on 17/6/12.
 */

public class ChangePhoneOrEmailPresenter {
    private final ChangePhoneOrEmailView changePhoneOrEmailView;
    private final ChangePhoneOrEmailModel changePhoneOrEmailModel;

    public ChangePhoneOrEmailPresenter(ChangePhoneOrEmailView changePhoneOrEmailView, ChangePhoneOrEmailModel changePhoneOrEmailModel) {
        this.changePhoneOrEmailView = changePhoneOrEmailView;
        this.changePhoneOrEmailModel = changePhoneOrEmailModel;
    }

    /**
     * 获取验证码
     *
     * @param type
     * @param number
     */
    public void lodeCode(boolean type, String number) {
        changePhoneOrEmailModel.lodeCode(type, number, new BaseCallBack() {
            @Override
            public void onSuccess(Object object) {
                changePhoneOrEmailView.loadCodeSuccess((JSONObject) object);
            }

            @Override
            public void onFailure() {
                changePhoneOrEmailView.loadCodeFailure();
            }

            @Override
            public void onFailure(Throwable throwable) {

            }
        });
    }

    /**
     * 验证验证码
     *
     * @param telephone
     * @param code
     */
    public void loadCheckCode(String telephone, String code) {
        changePhoneOrEmailModel.loadCheckCode(telephone, code, new BaseCallBack() {
            @Override
            public void onSuccess(Object object) {
                changePhoneOrEmailView.loadCheckCodeSuccess((JSONObject) object);
            }

            @Override
            public void onFailure() {
                changePhoneOrEmailView.loadCheckCodeFailure();
            }


            @Override
            public void onFailure(Throwable throwable) {

            }
        });
    }

    /**
     * 账号重置
     * @param type
     * @param oldName
     * @param newName
     */
    public void loadReset(boolean type, String oldName, String newName) {
        changePhoneOrEmailModel.loadReset(type, oldName, newName, new BaseCallBack() {
            @Override
            public void onSuccess(Object object) {
                changePhoneOrEmailView.loadResetSuccess((JSONObject)object);
            }

            @Override
            public void onFailure() {
                changePhoneOrEmailView.loadResetFailure();
            }

            @Override
            public void onFailure(Throwable throwable) {

            }
        });
    }
}
